package com.campusnews.controller;


import com.campusnews.annotation.LoginToken;
import com.campusnews.pojo.FirstComment;
import com.campusnews.service.FirstCommentService;
import com.campusnews.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lqc
 * @since 2021-09-26
 */
@RestController
@RequestMapping("/firstComment")
@Api(tags={"一级评论API"})
public class FirstCommentController {

    @Autowired
    private FirstCommentService firstCommentService;



//    @LoginToken
//    @ApiOperation(value = "修改一级评论信息", notes = "修改一级评论信息")
//    @RequestMapping(value = "/updateFirstComment" ,method = RequestMethod.POST)
//    public JsonResult updateFirstComment(@RequestBody FirstComment firstComment) {
//        return firstCommentService.updateFirstComment(firstComment);
//    }
//
//    @LoginToken
//    @ApiOperation(value = "添加一级评论信息", notes = "添加一级评论信息")
//    @RequestMapping(value = "/insertFirstComment" ,method = RequestMethod.POST)
//    public JsonResult insertFirstComment(@RequestBody FirstComment firstComment) {
//        return firstCommentService.insertFirstComment(firstComment);
//    }

    @LoginToken
    @ApiOperation(value = "删除一级评论信息", notes = "删除一级评论信息")
    @RequestMapping(value = "/deleteFirstComment" ,method = RequestMethod.POST)
    public JsonResult deleteFirstComment(@RequestBody FirstComment firstComment) {
        return firstCommentService.deleteFirstComment(firstComment);
    }

    @LoginToken
    @ApiOperation(value = "获取一级评论评论信息", notes = "获取一级评论评论信息")
    @RequestMapping(value = "/getComment/{inviId}/{sortOrder}" ,method = RequestMethod.GET)
    public JsonResult getComment(@PathVariable("inviId")int inviId,@RequestParam(value = "sortOrder",required = false)String sortOrder) {//按sortOrder排序
        List<FirstComment> commentList = firstCommentService.getInviteCommentInformation(inviId,0,sortOrder);
        return JsonResult.build(200,"评论获取成功",commentList);
    }
}

